<template>
  <vue-ueditor-wrap
    ref="ueditor"
    v-model="currentValue"
    :config="config"
    :destroy="true"
    :init="init"/>
</template>

<script>
  // 参考 https://github.com/HaoChuan9421/vue-ueditor-wrap
  import config from './ueditor.config'
  import extBtns from './button';
  import buttonD2admin from './button/modules/d2admin'
  import inputBtn from './button/modules/input'

  export default {
    props: {
      value: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        config,
        currentValue: ''
      }
    },
    watch: {
      // 对外提供 v-model
      value: {
        handler(val) {
          if (this.currentValue !== val) {
            this.currentValue = val
          }
        },
        immediate: true
      },
      // 对外提供 v-model
      currentValue(val) {
        this.$emit('input', val)
      }
    },
    methods: {
      init() {
        // 注册一个测试按钮
        // for (let type in extBtns.modules) {
        //   this.$refs.ueditor.registerButton(extBtns.modules[type]);
        // }
        this.$refs.ueditor.registerButton(buttonD2admin)
        this.$refs.ueditor.registerButton(inputBtn)
      }
    }
  }
</script>
<style lang="scss">
  .edui-editor-bottomContainer {
    display: none;
  }
</style>
